$(function() {

	$('#huodg7').datagrid({
		//请求地址
	    url:'../check/getcheckAffairApply3',
	    columns:[[
	    	{field:'',title:'',checkbox:true},
			{field:'applyId',title:'申请编号',width:'8%'},
			{field:'empId',title:'员工编号', width:'8%',
				formatter: function(value,row,index){
					if (row.emp){
						return row.emp.empId;
					} else {
						return "";
					}
				}},
				{field:'emp.empName',title:'员工名称', width:'10%',
					formatter: function(value,row,index){
						if (row.emp){
							return row.emp.empName;
						} else {
							return "";
						}
					}},
					{field:'emp.dep.depName',title:'部门名称', width:'10%',
						formatter: function(value,row,index){
							if (row.emp.dep){
								return row.emp.dep.depName;
							} else {
								return "";
							}
						}},
			{field:'holidayType',title:'事务类型',width:'8%'},
			{field:'reason',title:'原因',width:'20%'},
			{field:'beginTime',title:'开始时间',width:'17%'},
			{field:'endTime',title:'结束日期',width:'17%'},
			{field:'fileDocuments',title:'文件凭证',width:'10%'},
			{field:'approvalStatus',title:'审批状态', width:'8%',
				formatter: function(value,row,index){
					if (row.checkNotarizeAffair){
						return row.checkNotarizeAffair.approvalStatus;
					} else {
						return "";
					}
				}},
			{field:'maker',title:'创建者',width:'8%'},
			{field:'makeTime',title:'创建日期',width:'17%'},
			{field:'state',title:'状态',width:'7%',
				formatter : function(value, row, index) {
					if (row.state==='是') {
					var btns = "<a href='#' name='opera7' class='easyui-linkbutton'></a>";
					return btns;
					}
				}
			} ] ],
			onLoadSuccess : function() {
				$("a[name='opera7']").linkbutton({
					plain : true,
					iconCls : 'icon-back',
				});
				$("a[name='opera7']").bind('click',function(){
					var rows = $('#huodg7').datagrid('getSelected');
					var applyId=$("#applyId").val(rows.applyId);
					$.messager.confirm('请确认','您确定要打回提交的数据吗？',function(r){
						if(r){
							$("#back").window("open");
						}
						
					})
					
				});
				$("#huoedit7").bind('click',function(){
					var rows = $('#huodg7').datagrid('getSelected');
					if(rows.applyId!=null||rows.applyId==""){
						$("#applyId").val(rows.applyId);
						$("#getemp").val(rows.emp.empId);
						$("#holidayType").val(rows.holidayType);
						$("#reason").val(rows.reason);
						$("#beginTime").val(rows.beginTime);
						$("#makeTime").val(rows.endTime);
						$("#endTime").val(rows.fileDocuments);
						$("#huodd7").window("open");
					}else{
						alert("未勾选数据");
					}
				})
			},
	    fit:true,
	    //fit:true
	    fitColumns:true,
	    //隔行变色
	    striped:true,
	    nowrap:true,
	    //显示行号
	    rownumbers:true,
	    //设置单选
	    singleSelect:true,
		toolbar:'#huotb7',
		//显示分页栏
		pagination:true,
		//设置每页大小
		pageSize:7,
		//可选的每页大小
		pageList:[7,10,20,70]
	});
});
 function searchname(value){
	 $('#huodg7').datagrid('load','../check/serchcheckAffairApply3?value='+value);
} 
 
 var editIndex = undefined;
	function onClickCell(index, field){
		if (editIndex != index){
			if (endEditing()){
				$('#huodg7').datagrid('selectRow', index)
						.datagrid('beginEdit', index);
				var ed = $('#huodg7').datagrid('getEditor', {index:index,field:field});
				if (ed){
					($(ed.target).data('textbox') ? $(ed.target).textbox('textbox') : $(ed.target)).focus();
				}
				editIndex = index;
			} else {
				setTimeout(function(){
					$('#huodg7').datagrid('selectRow', editIndex);
				},0);
			}
		}
	}
	function removeit(){
		if (editIndex == undefined){
			var rows = $('#huodg7').datagrid('getSelections');
			if(rows.length > 0){
				$.messager.confirm('请确认','您确定要删除当前所有选中的项目吗？',function(r){
					if(r){
						var applyIds = [];
						for(var i = 0; i < rows.length; i++){
							applyIds.push(rows[i].applyId)
						}
						var huo_rowData = JSON.stringify(applyIds);
						alert(huo_rowData);
						$.ajax({
							url : "../check/deleteAffairApply",
							data : {"jsondata" : huo_rowData},
							success : function(e) {
								if (e == "ok") {
	                               alert("删除成功");
	                               $('#huodg7').datagrid('load');
								}
							}
						});
					}
				 })
				}
		}
		$('#huodg7').datagrid('cancelEdit', editIndex).datagrid('deleteRow', editIndex);
		editIndex = undefined;
	}
